# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_rjCMS_session_id'
  # Normalize unicode
  normalize_unicode_params :form => :c
  # Fix encoding for safari
  after_filter :fix_unicode_for_safari
  
  def fix_unicode_for_safari 
    if headers["Content-Type"] == "text/html; charset=utf-8" and request.env['HTTP_USER_AGENT'].to_s.include? 'AppleWebKit' and request.xhr?
      response.body.gsub!(/([^\x00-\xa0])/u) { |s| "&#x%x;" % $1.unpack('U')[0] }
    end
  end
  
end
